<?php
	//本页面作为API接口使用
		
	include_once("./public/common.php");
	
	
	//1.得到get参数并检测(->post)
	$dataSet = urldecode(getGETPara('dataSet'));
	$startTime = urldecode(getGETPara('startTime'));
	$frequence = urldecode(getGETPara('frequence'));
	$hashuser = urldecode(getGETPara('hashuser'));
	$hashdevice = urldecode(getGETPara('hashdevice'));
	/*
	echo "$dataSet |";
	echo "$startTime |";
	echo "$frequence |";
	echo "$hashuser |";
	echo "$hashdevice |";
	*/
	
	if($dataSet == null || $startTime == null || $frequence == null || $hashuser == null || $hashdevice == null){
		echo "fail";
		return false;
	}
	
	include_once("./public/opDB.php");
	include_once("./public/verify.php");
	
	$res = verifyUserAndDevice($hashuser,$hashdevice);
	if($res == null){
		echo "fail";
		return false;
	}
	//return the uid (not used) and did
	$uid = $res[0];
	$did = $res[1];
	
	$res = mysql_query('INSERT INTO `sensordata` (`sid`, `did`, `sdata`, `start`, `frequence`, `delflag`) VALUES (NULL, \''.$did.'\', \''.$dataSet.'\',\''.$startTime.'\', \''.$frequence.'\', \'0\')');
	if(!$res)
		echo "fail";
	else
		echo "OK";
?>